﻿using System.Windows.Input;
using Agnes.Core;
using System.Collections.Specialized;
using Caliburn.Micro;

namespace Agnes.Mainframe
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow
    {
        /// <summary>
        /// 用于绑定界面的主View
        /// </summary>
        public MainframeView MainframeContent { get; private set; }

        /// <summary>
        /// 构造函数
        /// </summary>
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            CommandBindings.AddRange(AgnesCommandService.CommandBindings);
            AgnesCommandService.CommandBindings.CollectionChanged += CommandBindingsCollectionChanged;
            
            MainframeViewModel vm = new MainframeViewModel();
            MainframeContent = new MainframeView();
            ViewModelBinder.Bind(vm, MainframeContent, null);
        }

        void CommandBindingsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            if (e.Action == NotifyCollectionChangedAction.Add)
                CommandBindings.AddRange(e.NewItems);
            else if (e.Action == NotifyCollectionChangedAction.Remove)
            {
                foreach (CommandBinding i in e.OldItems)
                    CommandBindings.Remove(i);
            }
        }



    }
}
